/* Papastefanos Serafeim */
/* Sunarthseis gia parsing soap mhnumatwn */

#include <stdio.h>
#include <upnp/ixml.h>
#include "client.h"
#include "helpers.h"

/************ 
 Oi akolou9es sunarthseis kanoun parse ena SOAP message 
 ************/

// Prepei na klh9ei kat' arxhn h parseStart gia na arxisei to parsing tou mhnumatos, kai
// akolou9ws arkei na klh9ei kapoia apo tis epomenes pairnontas ws parametro to pedio 
// message tou SoapMessage pou 9a epistreyei h parseStart.
SoapMessage *parseStart(char *buf);

// Kanei parse ena mhnuma Inform gemizontas katallhlha ta structs. To node prepei na einai
// to pedio message enos SoapMessage pou exei epistrafei apo thn parseStart
int parseInform(IXML_Node *node, DeviceIdStruct *deviceId, EventList *events, unsigned int *maxEnvelopse, DateTime *currentTime, unsigned int *retryCount, ParameterValueList *parameterList);

// Paromoiws gia to InformResponse
int parseInformResponse(IXML_Node *node, unsigned int *maxEnvelopes);

// Paromoiws gia to SetParameterValues
int parseSetParameterValues(IXML_Node *node, ParameterValueList *parameterList, char **parameterKey);

// Paromoiws gia to SetParameterValuesResponse
int parseSetParameterValuesResponse(IXML_Node *node, unsigned int *status);

// Paromoiws gia to GetParameterValues
int parseGetParameterValues(IXML_Node *node, StringList *parameterNames);

// Paromoiws gia to GetParameterValuesResponse
int parseGetParameterValuesResponse(IXML_Node *node, ParameterValueList *parameterList);

// Paromoiws gia to GetParameterNames
int parseGetParameterNames(IXML_Node *node, char **pathName, unsigned short *nextLevel);

// Paromoiws gia to GetParameterNamesResponse
int parseGetParameterNamesResponse(IXML_Node *node, StringList *parameterNames);

// Paromoiws gia to GetRPCMethods
int parseGetRPCMethods(IXML_Node *node);

// Paromoiws gia to GetRPCMethodsResponse
int parseGetRPCMethodsResponse(IXML_Node *node, StringList *);

// Paromoiws gia to Reboot
int parseReboot(IXML_Node *node, char **cmdKey);

// Paromoiws gia to RebootResponse
int parseRebootRespones(IXML_Node *node);

// Paromoiws gia to Download
int parseDownload(IXML_Node *node, char **cmdKey, char **fileType, char **URL, char **userName, char **passWord, unsigned int *fileSize, char **targetFileName, unsigned int *delaySeconds, char **successURL, char **failureURL);

// Paromoiws gia to DownloadResponse
int parseDownloadRespones(IXML_Node *node, short int *status, DateTime *stime, DateTime *ctime);

// Paromoiws gia to Upload
int parseUpload(IXML_Node *node, char **cmdKey, char **fileType, char **URL, char **userName, char **passWord, unsigned int *delaySeconds);

// Paromoiws gia to UploadResponse
int parseUploadRespones(IXML_Node *node, short int *status, DateTime *startTime, DateTime *completeTime);

// h parseHeader kanei parse ena header element kai epistrefei ws apotelesma mia domh SoapHeader
SoapHeader *parseHeader(IXML_Node *node);

// Boh9htikh sunarthsh. Ejetazei an to node exei ws onoma to nameOfNode kai an nai epistrefei ena char *
// me to keimeno autou tou node. Se periptwsh sfalmatos epistrefetai to NULL. To node prepei na periexei
// MONO keimeno kai oxi alla nodes ws paidia.
char *getNodeText(IXML_Node *node, char *nameOfNode);
